package org.nix.dto;

import org.nix.entity.City;
import org.nix.entity.CityDistance;

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;

/**
 * Create by zhangpe0312@qq.com on 2018/4/19.
 */
public class CityWayDto {

    // 路径
    private Queue<City> ways;

    // 距离
    private double extent;

    private List<CityDistance> cityDistances;

    public CityWayDto(Queue<City> ways, double extent, List<CityDistance> cityDistances) {
        this.ways = ways;
        this.extent = extent;
        this.cityDistances = cityDistances;
        handler();
    }

    public Queue<City> getWays() {
        return ways;
    }

    public void setWays(Queue<City> ways) {
        this.ways = ways;
    }

    public double getExtent() {
        return extent;
    }

    public void setExtent(double extent) {
        this.extent = extent;
    }

    public List<CityDistance> getCityDistances() {
        return cityDistances;
    }

    public void setCityDistances(List<CityDistance> cityDistances) {
        this.cityDistances = cityDistances;
    }

    private void handler() {
        List<CityDistance> temp = new ArrayList<>();
        for (CityDistance cityDistance : cityDistances) {

            CityDistance dis = new CityDistance();
            dis.setDistance(cityDistance.getDistance());

            City form = new City();
            form.setCityName(cityDistance.getFromCity().getCityName());
            dis.setFromCity(form);
            City to = new City();
            to.setCityName(cityDistance.getToCity().getCityName());

            dis.setFromCity(form);
            dis.setToCity(to);

            temp.add(dis);
        }

        cityDistances.clear();
        cityDistances.addAll(temp);
    }
}
